package com.da.springtest.ioc.create;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author chenlida
 * @date 2020/6/13 21:52
 * @description
 */
public class TestMethod {
    public static void main(String[] args) {
        //1.bean配置文件位置
        String beanXml = "classpath:bean/beanCreate.xml";
        //2.创建ClassPathXmlApplicationContext容器，给容器指定需要加载的bean配置文件
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);

        System.out.println("spring容器中所有bean如下：");

        //getBeanDefinitionNames用于获取容器中所有bean的名称
        for (String name : context.getBeanDefinitionNames()) {
            System.out.println(context.getBean(name));
        }

        System.out.println("--------------------------");
        //多次获取createByFactoryBean看看是否是同一个对象
        System.out.println("createByFactoryBean:" + context.getBean("createByFactoryBean"));
        System.out.println("createByFactoryBean:" + context.getBean("createByFactoryBean"));

    }
}
